from rest_framework import status
from rest_framework.generics import ListAPIView, ListCreateAPIView
from rest_framework.response import Response

from apps.users.models import User
from meiduo_mall_admin.meiduo_admin.serializers import UserSearchSerializer, PagNun


class UserSearchView(ListCreateAPIView):
  # queryset = User.objects.all()
  serializer_class = UserSearchSerializer
  pagination_class = PagNun

  def get_queryset(self):
    keyword = self.request.query_params.get('keyword')

    if keyword is '' or keyword is None:
      return User.objects.all()
    else:
      return User.objects.filter(username__contains=keyword)
